<?php


require_once  $_SERVER['DOCUMENT_ROOT']."/../_lib/base/common.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.template.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.destinations.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.photos.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.hotels.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.exchange_rates.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.airports.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.reviews.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.breadcrumb.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.lurls.php";
require_once SITE_ROOT_PATH."/_lib/classes/class.hotel_references.php";

session_start();

// check for search results and booking timeouts (see: common.php)
if($location = check_timeouts()) {
  header("Location: $location");
  exit;
}

	$airports = new airports();
	$hotels = new hotels();
	$destinations = new destinations();
	$photos = new photos();
	$reviews = new reviews();
	$lurls = new lurls();
	$breadcrumb = new breadcrumb();
	
	// get the hotel values
	$params['tree_id'] = $_GET['tree_id'];
	$hotel_values = $hotels->get_hotel($params);
	unset($params);
	
	// get parent resort
	$params['type_id'] = '2';
	$params['tree_id'] = $hotel_values['parent_id'];
	$resort_values = $tree->get_branch($params);
	$resort_values = $resort_values[0];
	unset($params);
	
	// get parent destination
	$params['type_id'] = '1';
	$params['tree_id'] = $resort_values['parent_id'];
	$destination_values = $tree->get_branch($params);
	$destination_values = $destination_values[0];
	unset($params);
	
	
	// get photos
	$hotel_photos = $photos->get_photos($hotel_values['tree_id']);
	$lead_hotel_thumb_url = UPLOAD_HTTP_PERM.$hotel_photos[0]['photo_url_thumb'];
	if(!$hotel_photos){
		$lead_hotel_thumb_url = UPLOAD_HTTP_PERM."photo_thumb_no_photo.gif";
	}
	

	// Get reviews
	$params['tree_id'] = $hotel_values['tree_id'];
	$params['status'] = 'a';
	$hotel_reviews = $reviews->get_review_average($params);
	if($hotel_reviews){
		$hotel_reviews_list = $reviews->get_reviews($params);
	}
	
	
	// Get LURL of the reviews
	$params['tree_id'] = $hotel_values['tree_id'];
	$lurl_review_add = $lurls->get_hotel_review_add_lurl($params);
	unset($params);
	// Get LURL of the reviews
	$params['tree_id'] = $hotel_values['tree_id'];
	$lurl_review_read = $lurls->get_hotel_review_lurl($params);
	unset($params);

  
	// Set the title
	$title = "Last minute holiday to ".$hotel_values['name'].", ".$resort_values['name'].", ".$destination_values['name']." holiday from ".$departure_airport_name;
	
	// set the META KEYWORDS
	$meta_keywords = $hotel_values['name'].", ".$resort_values['name'].", ".$destination_values['name']." holidays, budget travel, holiday to ".$destination_values['name'].", holidays from ".$departure_airport_name.", ".date('jS F',mktime(0, 0, 0,$dm,$dd,$dy)).", last minute,  ".$holiday_values['nights']." nights, cheap holidays, from Ireland, ".$resorts_string.", Budget travel, last minute, lastminute, Holiday Deals, holidays";
	
	// Set the META DESCRIPTION
	$meta_description = "Last minute holiday to ".$resort_values['name'].", ".$destination_values['name']." from ".$departure_airport_name.". Staying in ".$hotel_values['name']." hotel for ".$holiday_values['nights']." nights.";
	
		
	
	$template = new template();	
	$template->title = $title;
	$template->meta_keywords = $meta_keywords;
	$template->meta_description = $meta_description;
	$template->section_highlight = "hotels";
	$template->left_col = true;
	$template->search_tab = "hotels";
	$template->breadcrumbs_html = $breadcrumb->get_html_breadcrumb($hotel_values['tree_id']);
	$template->ld_head();
	
	$results = $_SESSION["hotels_search_results"]["data"];
	$hotel_id = intval($_GET['tree_id']);
	$hotel = $results["hotels"][$hotel_id];

	
	$ref_value['hotel_name'] = $hotel['hotel_name'];
	$ref_value['hotel_id_supplier'] = $hotel['hotel_id_youtravel'];
	$ref_value['tree_id'] = $hotel_id;
	$ref_value['check_in_date'] = $results["arrival_date"];
	$ref_value['nights'] = $results["nights"];
	$ref_value['rooms_count'] = $results["rooms_count"];
	$ref_value['room_breakdown'] = $results["room_breakdown"];
	
	$i=1;
	foreach($hotel["room_sets"] as $room_set){
		$room_breakdown .= "ROOM ".$i." ######################## \n";
		$room_breakdown .= "Adults = ".$room_set['adults']."\n";
		$room_breakdown .= "Children = ".$room_set['children']."\n";
		foreach($room_set['rooms'] as $room){
			$room_breakdown .= $room['Type']." ".$room['Board']." ".$room['Rate']."EURO\n";
		}
		$room_breakdown .= "\n\n";
		$i++;
	}
	//print_r($hotel["room_sets"]);
	$ref_value['room_breakdown'] = $room_breakdown;
	//echo $room_breakdown;
	$hotel_references = new hotel_references();
	$reference_id = $hotel_references->insert_reference($ref_value);
	
	
	

	// need variable pass mechanism to use it
	// $template->display("hotel.php");
	// for now just:
 	include SITE_ROOT_PATH."/_lib/html/hotel.php";

	// Display  dates
	// Display rates

 	include SITE_ROOT_PATH."/_lib/html/hotel_details_tabs.php";
	include SITE_ROOT_PATH."/_lib/html/pricing_terms.php";
//	var_dump($hotel_values);

	$template->ld_foot();
